package com.yixiaobai.swimming.common;

import com.yixiaobai.swimming.error.ErrorModel;
import lombok.Data;

/**
 * @author yuyunlong
 * @date 2020/7/4 12:53 下午
 * @description
 */
@Data
public class ResponseData<T> {
    private Boolean success = true;
    private int code = 200;
    private String message = "请求成功";
    private T data;

    /**
     * 构建response data
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResponseData<T> build(T data) {
        ResponseData<T> responseResult = new ResponseData<>();
        responseResult.setCode(200);
        responseResult.setData(data);
        return responseResult;
    }

    public static <T> ResponseData<T> buildErr(ErrorModel errorModel) {
        ResponseData<T> responseErr = new ResponseData<>();
        responseErr.setCode(errorModel.getErrCode());
        responseErr.setSuccess(false);
        responseErr.setMessage(errorModel.getErrMsg());
        return responseErr;
    }


}
